import 'package:flutter/material.dart';


/*class SettingPage extends StatefulWidget {
  const SettingPage({Key? key}) : super(key: key);

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("设置"),
    );
  }
}*/

class SettingPage extends StatelessWidget {
  const SettingPage({super.key});


  @override
  Widget build(BuildContext context) {
    return Container(
        child: Center(child: ButtonList()), // 将ButtonList作为主体部件显示
    );
  }
}

// 自定义的StatefulWidget类，用于管理列表数据并构建UI
class ButtonList extends StatefulWidget {
  const ButtonList({super.key});

  @override
  _ButtonListState createState() => _ButtonListState();
}

class _ButtonListState extends State<ButtonList> {
  final List<String> buttonTexts = ['Button1', 'Button2', 'Button3']; // 初始化按钮文本列表

  void updateButtons() {
    setState(() {
      for (int i = 0; i < buttonTexts.length; i++) {
        buttonTexts[i] += '_updated'; // 修改每个按钮的文本内容
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          child: const Text('Update Buttons'),
          onPressed: () {
            updateButtons(); // 点击按钮后调用updateButtons函数进行更新操作
          },
        ),

        Expanded(
          child: ListView.builder(
              itemCount: buttonTexts.length,
              itemBuilder: (context, index) {
                String text = buttonTexts[index];

                return Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ElevatedButton(
                    onPressed: null,
                    child: Text(text), // 这里设置onPressed为null，因此按钮不会有任何功能
                    style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(Colors.red),
                        foregroundColor:
                        MaterialStateProperty.all(Colors.white),
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10)
                        )
                        )
                    ),
                  ),
                );
              }),
        )
      ],
    );
  }
}